package school.community.config;

import school.community.interceptor.SessionInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 自定义MVC控件
 */
@Configuration
public class MyMvcConfig implements WebMvcConfigurer {

  @Autowired
  private SessionInterceptor sessionInterceptor;

  @Override
  public void addViewControllers(ViewControllerRegistry registry) {
    registry.addViewController("/").setViewName("index");
    registry.addViewController("/adminLogin.html").setViewName("adminLogin");
  }

  //自定义的国际化组键就生效了，将其装配到
  @Bean
  public LocaleResolver localeResolver() {
    return new MyLocalResolver();
  }

  @Override
  public void addInterceptors(InterceptorRegistry registry) {
    registry.addInterceptor(sessionInterceptor).addPathPatterns("/**");
  }
}
